const commonEnabled = {
  // boost: {
  //   useGPUTranslations: true,
  //   usePreallocated: true //缓存区分配，但是是试用性Api
  // },
  credits: {
    enabled: false //删除logo
  },
  time: {
    timezoneOffset: new Date().getTimezoneOffset() // 设置时区 东8 -480
  },
  stockTools: {
    gui: {
      enabled: false //左边画线工具
    }
  },
  rangeSelector: {
    //右上角有个日期区间
    enabled: false
  },
  plotOptions: {
    //自定义交互
    series: {
      animation: false,
      states: {
        //取消高亮
        hover: {
          enabled: false
        },
        inactive: {
          enabled: false
        }
      },
      marker: {
        enabled: undefined, //默认值
        enabledThreshold: Number.MAX_SAFE_INTEGER
      }
    },
    candlestick: {
      grouping: false
    },
    column: {
      minPointLength: 1 //柱子最小长度，为0的时候也有高度
    }
  },
  //自定义配置绘图工具
  bindings: {}
};

// 数据生成函数
const generateOHLCData = (days = 200): [number, number, number, number, number][] => {
  const data: [number, number, number, number, number][] = [];
  let date = new Date();
  date.setDate(date.getDate() - days);
  let price = 100;

  for (let i = 0; i < days; i++) {
    if (date.getDay() === 0 || date.getDay() === 6) {
      date.setDate(date.getDate() + 1);
      continue;
    }

    const timestamp = date.getTime();
    const open = +price.toFixed(2);
    const change = (Math.random() - 0.48) * 4;
    const close = +(open + change).toFixed(2);
    const high = +Math.max(open, close, open + Math.random() * 3).toFixed(2);
    const low = +Math.min(open, close, open - Math.random() * 3).toFixed(2);

    data.push([timestamp, open, high, low, close]);

    price = close;
    date.setDate(date.getDate() + 1);
  }

  return data;
};

export { commonEnabled, generateOHLCData };
